package com.lhx.product.service.impl;

import com.lhx.product.domain.SkuStock;
import com.lhx.product.mapper.SkuStockMapper;
import com.lhx.product.service.SkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author：李洪祥
 * @Package：com.lhx.product.service.impl
 * @Project：lhx-RuoYi
 * @name：SkuStockServiceImpl
 * @Date：2024/6/3 下午9:07
 */
@Service
public class SkuStockServiceImpl implements SkuStockService {


    @Autowired
    private SkuStockMapper skuStockMapper;


    @Override
    public List<SkuStock> getList(Long pid, String keyword) {
        return skuStockMapper.getList(pid,keyword);
    }

    /**
     * 批量更新库存信息
     * @param pid
     * @param skuStockList
     * @return
     */
    @Override
    public int update(Long pid, List<SkuStock> skuStockList) {
        List<SkuStock> filterSkuList =  skuStockList.stream()
                .filter(item->pid.equals(item.getProductId()))
                .collect(Collectors.toList());
        return skuStockMapper.replaceList(skuStockList);
    }
}
